/* 
 * @description: 布局组件封装
 * @author: Jane 
 * @date: 2023-09-15 15:39:01
 */
import 'package:basic_common/app_theme.dart';
import 'package:basic_common/common_exports.dart';
import 'package:flutter/cupertino.dart';
/// 信息显示Item
Widget buildInfoItem(
    {required String attrName,
    required Widget rightWidget,
    bool isBold = false}) {
  return Container(
    width: ScreenHelper.screenWidth,
    height: ScreenHelper.height(40),
    padding: EdgeInsets.symmetric(
        horizontal: ScreenHelper.width(8), vertical: ScreenHelper.height(4)),
    decoration:const BoxDecoration(
        color: Colors.white,
        border:
            Border(bottom: BorderSide(color: AppTheme.dividerColor, width: 1))),
    child: Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        Text(
          attrName,
          style: TextStyle(
              color: AppTheme.seconddarkWeakTextColor,
              fontSize: ScreenHelper.sp(16),
              fontWeight: isBold ? FontWeight.bold : FontWeight.normal),
        ),
        rightWidget
      ],
    ),
  );
}

/// 下拉刷新组件
Widget refreshBox(
    {required void Function()? onRefresh,
    required void Function()? onLoading,
    required RefreshController refController,
    required Widget child,
    isShowUp = true,
    reverse = false,
    isShowDown = true}) {
  return SmartRefresher(
      enablePullDown: isShowDown,
      enablePullUp: isShowUp,
      enableTwoLevel: false,
      onRefresh: onRefresh,
      onLoading: onLoading,
      controller: refController,
      reverse: reverse,
      header: WaterDropHeader(
        complete: Text('刷新成功', style: TextStyle(color: Get.theme.primaryColor)),
      ),
      footer: CustomFooter(
        builder: (BuildContext context, LoadStatus? mode) {
          Widget body;
          if (mode == LoadStatus.idle) {
            body = Text(
              "上拉加载",
              style: TextStyle(color: Theme.of(context).primaryColor),
            );
          } else if (mode == LoadStatus.loading) {
            body = Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                CupertinoActivityIndicator(
                    color: Get.theme.textTheme.bodySmall!.color),
                SizedBox(width: ScreenHelper.width(5)),
                Text(
                  '消息加载中',
                  style: TextStyle(
                      fontSize: ScreenHelper.sp(16),
                      color: AppTheme.weakTextColor),
                )
              ],
            );
          } else if (mode == LoadStatus.canLoading) {
            body = Text("松手,加载更多!",
                style: TextStyle(color: Theme.of(context).primaryColor));
          } else {
            body = Text("",
                style: TextStyle(color: Theme.of(context).primaryColor));
          }
          return SizedBox(
            height: 55.0,
            child: Center(child: body),
          );
        },
      ),
      child: child);
}
